/**
 * 作者: chenlingzhi
 * 日期: 2025-03-03 20:30:45
 * 备注: 用户好友信息表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserBuddyModel extends BaseModel implements Model {
	public static final String LISTKEY = "user_id.buddy_id";
	public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
	public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
	public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

	protected long id; // ID
	protected long userId; // 用户ID
	protected long buddyId; // 好友ID
	protected long giftTime; // 赠礼时间
	protected int giftStatus; // 收到赠礼状态 (0没礼物1有礼物2已领取)
	protected long receiveGiftTime; // 收到赠礼时间

	public void reset() {
	}

	protected String getKey() {
		return "UserBuddy." + userId + "." + buddyId;
	}

	protected String getListKey() {
		return "UserBuddy." + userId;
	}

	protected String getListItemKey() {
		return buddyId + "";
	}

	public void doCreate() {
		setTableId();
		insert();
	}

	public void setTableId() {
		putId(incrTableId("user_buddy"));
	}

	public JsonObject insert() {
		return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	public void delete() {
		super.delete(getKey(), id, UPDATE_DB_TYPE, userId, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
	}

	/**
	 * 根据入库类型更新
	 */
	public JsonObject update() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, userId, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	/**
	 * 实时入队列
	 */
	public JsonObject updateQueueNow() {
		return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
	}

	public JsonObject getAllObj(){
		JsonObject obj = new JsonObject();
		obj.put("id", id); // ID
		obj.put("userId", userId); // 用户ID
		obj.put("buddyId", buddyId); // 好友ID
		obj.put("giftTime", giftTime); // 赠礼时间
		obj.put("giftStatus", giftStatus); // 收到赠礼状态 (0没礼物1有礼物2已领取)
		obj.put("receiveGiftTime", receiveGiftTime); // 收到赠礼时间
		return obj;
	}

	public long getId() {
		return id;
	}

	public void putId(long id) {
		if (this.id != id) {
			this.id = id;
			updateRedisHashField(getKey(), "id", this.id);
		}
	}

	public void addId(long value) {
		this.id += value;
		updateRedisHashField(getKey(), "id", this.id);
	}

	public long getUserId() {
		return userId;
	}

	public void putUserId(long userId) {
		if (this.userId != userId) {
			this.userId = userId;
			updateRedisHashField(getKey(), "userId", this.userId);
		}
	}

	public void addUserId(long value) {
		this.userId += value;
		updateRedisHashField(getKey(), "userId", this.userId);
	}

	public long getBuddyId() {
		return buddyId;
	}

	public void putBuddyId(long buddyId) {
		if (this.buddyId != buddyId) {
			this.buddyId = buddyId;
			updateRedisHashField(getKey(), "buddyId", this.buddyId);
		}
	}

	public void addBuddyId(long value) {
		this.buddyId += value;
		updateRedisHashField(getKey(), "buddyId", this.buddyId);
	}

	public long getGiftTime() {
		return giftTime;
	}

	public void putGiftTime(long giftTime) {
		if (this.giftTime != giftTime) {
			this.giftTime = giftTime;
			updateRedisHashField(getKey(), "giftTime", this.giftTime);
		}
	}

	public void addGiftTime(long value) {
		this.giftTime += value;
		updateRedisHashField(getKey(), "giftTime", this.giftTime);
	}

	public int getGiftStatus() {
		return giftStatus;
	}

	public void putGiftStatus(int giftStatus) {
		if (this.giftStatus != giftStatus) {
			this.giftStatus = giftStatus;
			updateRedisHashField(getKey(), "giftStatus", this.giftStatus);
		}
	}

	public void addGiftStatus(int value) {
		this.giftStatus += value;
		updateRedisHashField(getKey(), "giftStatus", this.giftStatus);
	}

	public long getReceiveGiftTime() {
		return receiveGiftTime;
	}

	public void putReceiveGiftTime(long receiveGiftTime) {
		if (this.receiveGiftTime != receiveGiftTime) {
			this.receiveGiftTime = receiveGiftTime;
			updateRedisHashField(getKey(), "receiveGiftTime", this.receiveGiftTime);
		}
	}

	public void addReceiveGiftTime(long value) {
		this.receiveGiftTime += value;
		updateRedisHashField(getKey(), "receiveGiftTime", this.receiveGiftTime);
	}

}